package com.fish.web.core.config;

import com.fish.common.constant.HttpStatus;
import com.fish.common.core.domain.AjaxResult;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.media.IntegerSchema;
import io.swagger.v3.oas.models.media.ObjectSchema;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.media.StringSchema;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 验证码操作处理
 *
 * @author Dftre
 */
@Configuration
public class SwaggerConfig {

    @Bean
    public OpenAPI springShopOpenAPI() {
        Schema<?> codeSchema = new IntegerSchema().example(HttpStatus.SUCCESS); // 示例状态码
        Schema<?> msgSchema = new StringSchema().example("操作成功"); // 示例消息
        ObjectSchema dataSchema = new ObjectSchema(); // 数据可以是任意类型，这里简单定义为ObjectSchema

        // 定义AjaxResult的Schema
        ObjectSchema ajaxResultSchema = new ObjectSchema();
        ajaxResultSchema.addProperty(AjaxResult.CODE_TAG, codeSchema);
        ajaxResultSchema.addProperty(AjaxResult.MSG_TAG, msgSchema);
        ajaxResultSchema.addProperty(AjaxResult.DATA_TAG, dataSchema);
        Components components = new Components();
        components.addSchemas("AjaxResult", ajaxResultSchema);

        return new OpenAPI().components(components).info(new Info().title("Fish Init").description("Fish Init API文档").version("1.0.1").license(new License().name("Apache 2.0").url("http://springdoc.org"))).externalDocs(new ExternalDocumentation().description("外部文档").url("/doc.html"));
    }

    /**
     * 系统模块
     */
    @Bean
    public GroupedOpenApi sysApi() {
        return GroupedOpenApi.builder().group("sys").packagesToScan("com.fish.web.controller.system").build();
    }

    /**
     * 基础模块
     */
    @Bean
    public GroupedOpenApi commonApi() {
        return GroupedOpenApi.builder().group("base").packagesToScan("com.fish.web.controller.common").build();
    }

    /**
     * 业务模块
     */
    @Bean
    public GroupedOpenApi projectApi() {
        return GroupedOpenApi.builder().group("service").packagesToScan("com.fish.web.controller.project").build();
    }

}
